<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk">

    <f:view>
        <f:loadBundle var="text" basename="#{productList.bundleName}"/>
        <head>
            <title>#{text['productList.title']}</title>
            <meta name="heading" content="#{text['productList.heading']}"/>
            <meta name="menu" content="CatalogsMenu"/>
        </head>
        <body id="productList">
        <h:form id="editproduct">

            <h:commandButton value="#{text['button.search']}"  action="#{productList.execute}" id="search" styleClass="button" style="margin-left: 5px"/>
            <h:commandButton value="#{text['button.add']}" action="add" id="add" immediate="true" styleClass="button"/>
            <h:commandButton value="#{text['button.done']}" action="mainMenu" id="close" immediate="true" styleClass="button"/>            

            <h:panelGroup>
                <table>
                    <tr>
                        <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="code" value="#{text['product.code']}"/>
                        <h:inputText styleClass="text medium" id="code" value="#{productList.code}"/>
                        <t:message for="code" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="description" value="#{text['product.description']}"/>
                        <h:inputText styleClass="text medium" id="description" value="#{productList.description}"/>
                        <t:message for="description" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    </tr>
                    <tr>
                        <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="resolution" value="#{text['product.resolution']}"/>
                        <h:selectOneMenu value="#{productList.resolution}" id="resolution" styleClass="select">
                            <f:selectItem itemLabel="Todas"/>
                            <t:selectItems value="#{productList.resolutions}" var="resolution" itemLabel="#{resolution.description}" itemValue="#{resolution}"/>
                            <f:converter converterId="objconverter"/>
                        </h:selectOneMenu>
                        <t:message for="resolution" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="workType" value="#{text['product.workType']}"/>
                        <h:selectOneMenu value="#{productList.workType}" id="workType" styleClass="select">
                            <f:selectItem itemLabel="Todos"/>
                            <t:selectItems value="#{productList.workTypes}" var="workType" itemLabel="#{workType.description}" itemValue="#{workType}"/>
                            <f:converter converterId="objconverter"/>
                        </h:selectOneMenu>
                        <t:message for="workType" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    </tr>
                </table>
            </h:panelGroup>
            <!-- Error from this table is caused by http://issues.apache.org/jira/browse/TOMAHAWK-466 -->
            <t:dataTable id="products" var="product" style="margin-top: 10px"
                         value="#{productList.products}" rows="25" sortColumn="#{productList.sortColumn}"
                         sortAscending="#{productList.ascending}" styleClass="scrollerTable table"
                         headerClass="standardTable_Header" rowClasses="standardTable_Row1,standardTable_Row2"
                         columnClasses="standardTable_Column,standardTable_Column,standardTable_Column,standardTable_Column,standardTable_ColumnCentered">
                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="id" arrow="true">
                            <h:outputText value="#{text['product.id']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:commandLink action="#{productForm.edit}" value="#{product.id}">
                        <f:param name="id" value="#{product.id}"/>
                        <f:param name="from" value="list"/>
                    </h:commandLink>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="code" arrow="true">
                            <h:outputText value="#{text['product.code']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{product.code}" escape="true"/>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="description" arrow="true">
                            <h:outputText value="#{text['product.description']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{product.description}" escape="true"/>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="price" arrow="true">
                            <h:outputText value="#{text['product.price']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{product.price}" escape="true">
                        <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                    </h:outputText>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="unitMeasure" arrow="true">
                            <h:outputText value="#{text['product.unitMeasure']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{product.unitMeasure.description}" escape="true"/>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="resolution" arrow="true">
                            <h:outputText value="#{text['product.resolution']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{product.resolution.description}" escape="true"/>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="workType" arrow="true">
                            <h:outputText value="#{text['product.workType']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{product.workType.description}" escape="true"/>
                </t:column>

            </t:dataTable>

            <t:saveState id="save1" value="#{productList.products}"/>

            <ui:include src="/common/tableFooter.xhtml">
                <ui:param name="tableName" value="products"/>
            </ui:include>

            <script type="text/javascript">
                highlightTableRows("editproduct:products");
            </script>

        </h:form>
    </body>
</f:view>
</html>